package javachongkao.面向对象下.NCHU_图形继承;

import java.util.Scanner;

//7-18 NCHU_图形继承
//编写程序，实现图形类的继承，并定义相应类对象并进行测试。
//
//类Shape，无属性，有一个返回0.0的求图形面积的公有方法public double getArea();//求图形面积
//类Circle，继承自Shape，有一个私有实型的属性radius（半径），重写父类继承来的求面积方法，求圆的面积
//类Rectangle，继承自Shape，有两个私有实型属性width和length，重写父类继承来的求面积方法，求矩形的面积
//类Ball，继承自Circle，其属性从父类继承，重写父类求面积方法，求球表面积，此外，定义一求球体积的方法public double getVolume();//求球体积
//类Box，继承自Rectangle，除从父类继承的属性外，再定义一个属性height，重写父类继承来的求面积方法，求立方体表面积，此外，定义一求立方体体积的方法public double getVolume();//求立方体体积
//注意：
//每个类均有构造方法，且构造方法内必须输出如下内容：Constructing 类名
//每个类属性均为私有，且必须有getter和setter方法（可用Eclipse自动生成）
//输出的数值均保留两位小数
//主方法内，主要实现四个功能（1-4）：
//从键盘输入1，则定义圆类，从键盘输入圆的半径后，主要输出圆的面积；
//从键盘输入2，则定义矩形类，从键盘输入矩形的宽和长后，主要输出矩形的面积；
//从键盘输入3，则定义球类，从键盘输入球的半径后，主要输出球的表面积和体积；
//从键盘输入4，则定义立方体类，从键盘输入立方体的宽、长和高度后，主要输出立方体的表面积和体积；
//
//假如数据输入非法（包括圆、矩形、球及立方体对象的属性不大于0和输入选择值非1-4），系统输出Wrong Format
//
//输入格式:
//共四种合法输入
//
//1 圆半径
//2 矩形宽、长
//3 球半径
//4 立方体宽、长、高
//输出格式:
//按照以上需求提示依次输出
class Shape {
    public Shape() {
        System.out.println("Constructing Shape");
    }

    public double getArea() {
        return 0.0;
    }
}

class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        super();
        System.out.println("Constructing Circle");
        this.radius = radius;
    }

    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }
}

class Rectangle extends Shape {
    private double width;
    private double length;

    public Rectangle(double width, double length) {
        super();
        System.out.println("Constructing Rectangle");
        this.width = width;
        this.length = length;
    }

    @Override
    public double getArea() {
        return width * length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }
}

class Ball extends Circle {
    public Ball(double radius) {
        super(radius);
        System.out.println("Constructing Ball");
    }

    @Override
    public double getArea() {
        return 4 * Math.PI * getRadius() * getRadius();
    }

    public double getVolume() {
        return (4.0 / 3) * Math.PI * Math.pow(getRadius(), 3);
    }
}

class Box extends Rectangle {
    private double height;

    public Box(double width, double length, double height) {
        super(width, length);
        System.out.println("Constructing Box");
        this.height = height;
    }

    @Override
    public double getArea() {
        return 2 * (getWidth() * getLength() + getWidth() * height + getLength() * height);
    }

    public double getVolume() {
        return getWidth() * getLength() * height;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try {
            int choice = scanner.nextInt();

            switch (choice) {
                case 1: {
                    double radius = scanner.nextDouble();
                    if (radius <= 0) {
                        System.out.println("Wrong Format");
                        return;
                    }
                    Circle circle = new Circle(radius);
                    System.out.printf("Circle's area:%.2f\n", circle.getArea());
                    break;
                }
                case 2: {
                    double width = scanner.nextDouble();
                    double length = scanner.nextDouble();
                    if (width <= 0 || length <= 0) {
                        System.out.println("Wrong Format");
                        return;
                    }
                    Rectangle rectangle = new Rectangle(width, length);
                    System.out.printf("Rectangle's area:%.2f\n", rectangle.getArea());
                    break;
                }
                case 3: {
                    double radius = scanner.nextDouble();
                    if (radius <= 0) {
                        System.out.println("Wrong Format");
                        return;
                    }
                    Ball ball = new Ball(radius);
                    System.out.printf("Ball's surface area:%.2f\n", ball.getArea());
                    System.out.printf("Ball's volume:%.2f\n", ball.getVolume());
                    break;
                }
                case 4: {
                    double width = scanner.nextDouble();
                    double length = scanner.nextDouble();
                    double height = scanner.nextDouble();
                    if (width <= 0 || length <= 0 || height <= 0) {
                        System.out.println("Wrong Format");
                        return;
                    }
                    Box box = new Box(width, length, height);
                    System.out.printf("Box's surface area:%.2f\n", box.getArea());
                    System.out.printf("Box's volume:%.2f\n", box.getVolume());
                    break;
                }
                default:
                    System.out.println("Wrong Format");
            }
        } catch (Exception e) {
            System.out.println("Wrong Format");
        }
    }
}